let Mock=require('mockjs')
import {vueWeb,sproWeb,stuWeb,ziWeb} from './webData'
import {jiWeb,guWeb} from './caiData'
import { othWeb } from './othData'

type web={
   id:string;
   title:string;
   url:string;
   info:string
}


let yan=Mock.mock('/yan', ()=>{
    return Mock.Random.natural( 100000, 999999 )
})

let webnet=Mock.mock('/webnet',(params:any):any=>{
    
    if(params.body=='v'){
      return vueWeb
    }else if(params.body=='s'){
       return sproWeb
    }else if(params.body=='x'){
       return stuWeb
    }else if(params.body=='z'){
       return ziWeb
    }else if(params.body=='j'){
      return jiWeb
    }else if(params.body=='g'){
       return guWeb
    }else if(params.body=='o'){
      return othWeb
   }
    
    else{
       return  []
    }

    
})

let postNet=Mock.mock('/editNet',(data:any)=>{
   //修改网站备注
   let sdata=JSON.parse(data.body)
   let webType=getWebType(sdata.type)
   webType.forEach(item=>{
      if(item.id==sdata.id){
         item.info=sdata.text
      }
   })
})

let addNet=Mock.mock('/addNet',(data:any)=>{
   //新增网址
   let sdata=JSON.parse(data.body)

   let webType=getWebType(sdata.type)
   webType.push(sdata.data)

})

let del=Mock.mock('/delWeb',(data:any)=>{
   //删除网址
  
   let sdata=JSON.parse(data.body)
   let webType=getWebType(sdata.type)
   webType.forEach((item,index)=>{
      if(item.id==sdata.id){
         webType.splice(index,1)
      }
   })
})



function getWebType(type:string):web[]{
   if(type=='v'){
      return vueWeb
    }else if(type=='s'){
       return sproWeb
    }else if(type=='x'){
       return stuWeb
    }else if(type=='z'){
       return ziWeb
    }else if(type=='j'){
      return jiWeb
    }else if(type=='g'){
       return guWeb
    }else if(type=='o'){
      return othWeb
   }
    
    else{
       return  []
    }
}








